package com.udaos.modules.section.services;

import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

import com.udaos.common.base.Service;
import com.udaos.models.region.Ud_region;
import com.udaos.models.resource.Ud_wx_resource;
import com.udaos.models.section.Ud_wx_section;
import com.udaos.models.sys.Sys_user;
import com.udaos.modules.company.services.UdCompanyRegionService;
import com.udaos.modules.resource.services.UdWxResourceService;

/**
 * @author mutaotao
 * @time 2017-03-28 16:22:06
 * 
 */
@IocBean(args = { "refer:dao" })
public class UdWxSectionService extends Service<Ud_wx_section> {
	
	@Inject
	private UdCompanyRegionService companyRegionService;
	@Inject
	private UdWxResourceService resourceService;
	
	public UdWxSectionService(Dao dao) {
		super(dao);
	}
	
	/**
	 * 获取当前主体下开通的区域
	 * @return
	 */
	public List<Ud_region> getRegions() {
		Subject subject = SecurityUtils.getSubject();
		Sys_user user = (Sys_user) subject.getPrincipal();
		String company_id=user.getUnit().getCompany_id();
		return companyRegionService.findRegionById(company_id);
	}

	/**
	 * 获取资源
	 * @return
	 */
	public List<Ud_wx_resource> findResources() {
		Cnd cnd =Cnd.NEW();
		Subject subject = SecurityUtils.getSubject();
		Sys_user user = (Sys_user) subject.getPrincipal();
		String company_id=user.getUnit().getCompany_id();
		cnd.and("state", "=", 0);
		cnd.and("company_id", "=", company_id);
		cnd.and("delFlag", "=", "0");
		return resourceService.query(cnd);
	}
}